package com.touchportfolio.view
{
	import com.greensock.TweenLite;
	import com.touchportfolio.events.PayloadEvent;
	import com.touchportfolio.loadQueue.LoadQueue;
	import com.touchportfolio.loadQueue.loaders.ImageLoader;
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.Event;
	
	[Event(name="image_loaded", type="BigImage")]
	
	public class BigImage extends Sprite
	{
		public static const IMAGE_LOADED:String = "image_loaded";
		private var _imageLoader:ImageLoader;
		private var _q:LoadQueue;
		
		public function BigImage(url:String)
		{
			_q = LoadQueue.getInstance();
			_imageLoader = new ImageLoader(url);
			_imageLoader.addEventListener(PayloadEvent.PAYLOAD, onImageLoaded);
			_imageLoader.alpha = 0;
			_q.addTask(_imageLoader);
			
			addChild(_imageLoader);
		}
		
		private function onImageLoaded(e:PayloadEvent):void
		{
			var bt:Bitmap = Bitmap(e.payload.content);
			bt.smoothing = true;
			bt.cacheAsBitmap = true;
			
			TweenLite.to(_imageLoader, .3, {alpha:1});
			dispatchEvent(new Event(IMAGE_LOADED));
		}
	}
}